Telegram Group & Telegram Channel
🛠 How to: как соблюдать принцип DRY

DRY (Don’t Repeat Yourself) — принцип, согласно которому каждый фрагмент знания должен существовать в системе только в одном месте. Никакого копипаста и дублирующей логики.

Проблема: дублирование валидации
// Пример плохого кода
if (user.Age < 18)
throw new Exception("User must be at least 18");

...

if (user.Age < 18)
return BadRequest("User must be at least 18");

При изменении правила — нужно помнить обновить его везде. Ловушка копипаста.

Решение: вынос логики в общее правило
public static class ValidationRules
{
public static bool IsAdult(User user) => user.Age >= 18;
}


Теперь в коде
if (!ValidationRules.IsAdult(user))
throw new Exception("User must be at least 18");

// И в другом месте:
if (!ValidationRules.IsAdult(user))
return BadRequest("User must be at least 18");


Альтернатива: использование FluentValidation или DataAnnotations
public class User
{
[Range(18, int.MaxValue, ErrorMessage = "User must be at least 18")]
public int Age { get; set; }
}


Где чаще всего нарушают DRY в .NET:


• Повторяющиеся SQL-запросы и фильтры
• Повторение одинаковых exception'ов, логов, сообщений
• Дублирование конфигурации
• UI-формы и компоненты

🐸Библиотека шарписта #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/csharpproglib/5841
Create:
Last Update:

🛠 How to: как соблюдать принцип DRY

DRY (Don’t Repeat Yourself) — принцип, согласно которому каждый фрагмент знания должен существовать в системе только в одном месте. Никакого копипаста и дублирующей логики.

Проблема: дублирование валидации

// Пример плохого кода
if (user.Age < 18)
throw new Exception("User must be at least 18");

...

if (user.Age < 18)
return BadRequest("User must be at least 18");

При изменении правила — нужно помнить обновить его везде. Ловушка копипаста.

Решение: вынос логики в общее правило
public static class ValidationRules
{
public static bool IsAdult(User user) => user.Age >= 18;
}


Теперь в коде
if (!ValidationRules.IsAdult(user))
throw new Exception("User must be at least 18");

// И в другом месте:
if (!ValidationRules.IsAdult(user))
return BadRequest("User must be at least 18");


Альтернатива: использование FluentValidation или DataAnnotations
public class User
{
[Range(18, int.MaxValue, ErrorMessage = "User must be at least 18")]
public int Age { get; set; }
}


Где чаще всего нарушают DRY в .NET:


• Повторяющиеся SQL-запросы и фильтры
• Повторение одинаковых exception'ов, логов, сообщений
• Дублирование конфигурации
• UI-формы и компоненты

🐸Библиотека шарписта #буст

BY Библиотека шарписта | C#, F#, .NET, ASP.NET




Share with your friend now:
tg-me.com/csharpproglib/5841

View MORE
Open in Telegram


Библиотека шарписта | C F NET ASP NET Telegram | DID YOU KNOW?

Date: |

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

Look for Channels Online

You guessed it – the internet is your friend. A good place to start looking for Telegram channels is Reddit. This is one of the biggest sites on the internet, with millions of communities, including those from Telegram.Then, you can search one of the many dedicated websites for Telegram channel searching. One of them is telegram-group.com. This website has many categories and a really simple user interface. Another great site is telegram channels.me. It has even more channels than the previous one, and an even better user experience.These are just some of the many available websites. You can look them up online if you’re not satisfied with these two. All of these sites list only public channels. If you want to join a private channel, you’ll have to ask one of its members to invite you.

Библиотека шарписта | C F NET ASP NET from fr


Telegram Библиотека шарписта | C#, F#, .NET, ASP.NET
FROM USA